using System;
using System.Web.UI;
using MettleSystems.dashCommerce.Core;
using MettleSystems.dashCommerce.Core.Caching;
using MettleSystems.dashCommerce.Core.Configuration;
using OpenNetCommerce.Localization;
using MettleSystems.dashCommerce.Store;
using MettleSystems.dashCommerce.Store.Web.Controls;
using SubSonic.Utilities;

namespace MettleSystems.dashCommerce.Web.admin.controls.sitesettings
{
	public class SiteSettingsControl : AdminControl
	{

		#region Member Variables

		//private SiteSettings _siteSettings;
		protected string view;

		#endregion

		#region Page Events

		protected virtual void Page_Load(object sender, EventArgs e)
		{
			view = Utility.GetParameter("view");
		}

		#endregion

		#region Properties

		///// <summary>
		///// Gets the panel.
		///// </summary>
		///// <value>The panel.</value>
		//public Panel Panel {
		//  get {
		//    return this.FindControl("pnlSettings") as Panel;
		//  }
		//}

		/// <summary>
		/// Gets or sets the site settings.
		/// </summary>
		/// <value>The site settings.</value>
		public SiteSettings SiteSettings
		{
			get { return dashCommerce.Core.WebApplicationBase.SiteSettings; }
			//set { _siteSettings = value; }
		}

		#endregion

		#region Methods

		#region Public

		/// <summary>
		/// Saves the specified site settings.
		/// </summary>
		/// <param name="siteSettings">The site settings.</param>
		public void Save(SiteSettings siteSettings)
		{
			//try {
			//   DatabaseConfigurationProvider databaseConfigurationProvider = new DatabaseConfigurationProvider();
			//   int id = databaseConfigurationProvider.SaveConfiguration(SiteSettings.SECTION_NAME, siteSettings,
			//                                                            WebUtility.GetUserName());
			//   SiteSettingCache.RemoveSiteSettingsFromCache();
			//   if (id > 0) {
			//      MasterPage.MessageCenter.DisplaySuccessMessage(LocalizationUtility.GetText("lblSiteSettingsSaved"));
			//   }
			//   else {
			//      MasterPage.MessageCenter.DisplayFailureMessage(LocalizationUtility.GetText("lblSiteSettingsNotSaved"));
			//   }
			//}
			//catch (Exception ex) {
			//   Logger.Error("Save", ex);
			//   MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message);
			//}
			if (SiteSettings.Save(WebUtility.GetUserName())) {
				MasterPage.MessageCenter.DisplaySuccessMessage(LocalizationUtility.GetText("lblSiteSettingsSaved"));
			}
			else {
				MasterPage.MessageCenter.DisplayFailureMessage(LocalizationUtility.GetText("lblSiteSettingsNotSaved"));
			}
		}

		#endregion

		#endregion

	}
}
